package face.pay.rocket.listener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import face.pay.sharing.ISharingAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SharingAccountListener implements MessageListener {

    @Autowired
    ISharingAccountService iSharingAccountService;

    @Override
    public Action consume(Message message, ConsumeContext consumeContext) {
        System.out.println("Receive: " + message);
        try {

            String body = new String(message.getBody());
            this.iSharingAccountService.sharingAccount(body);

        } catch (Exception e) {
            log.error("分账 消费异常",e);
            //消费失败
        }
        return Action.CommitMessage;
    }

}
